using Sinacor.UI.Bovespa.Contabil.Communication;
using Sinacor.Infra.UI.Common;
using System.Collections.Generic;

namespace Sinacor.UI.Bovespa.Contabil.Communication.Translator.DataContractToModel
{
    public class DespesaNota
    {

        public DespesaNota() { }

        public Model.Conflito ToConflito(Bovespa.Contabil.DespesaNota.ConflitoResponse request) 
        {
            Model.Conflito to = new Sinacor.UI.Bovespa.Contabil.Model.Conflito();
            to.ExisteConflito = request.ExisteConflito;
            to.PermiteAjuste = request.PermiteAjuste; 
            return to;
		}

        public ModelCollection<Model.Conflito> ToConflito(List<Bovespa.Contabil.DespesaNota.ConflitoResponse> responseList)
        {
            ModelCollection<Model.Conflito> to = new ModelCollection<Sinacor.UI.Bovespa.Contabil.Model.Conflito>();

            foreach (Bovespa.Contabil.DespesaNota.ConflitoResponse item in responseList)
            {
                to.Add(ToConflito(item));
            }
            return to;
        }


        public Model.DespesaNota ToDespesaNota(Bovespa.Contabil.DespesaNota.DespesaNotaResponse response)
        {
            Model.DespesaNota to = new Sinacor.UI.Bovespa.Contabil.Model.DespesaNota();
            to.BaseDespesa = (Model.Enum.TipoBaseDespesa) response.BaseDespesa;
            to.Codigo = response.Codigo;

            if (response.EventoContabil != null)
            {
                to.EventoContabil = new Sinacor.UI.Bovespa.Contabil.Model.EventoContabil();
                to.EventoContabil.Codigo = response.EventoContabil.Codigo;
                to.EventoContabil.Descricao = response.EventoContabil.Descricao;
            }

            to.IncideIrrf = response.IncideIrrf;
            to.PercentualDespesa = response.PercentualDespesa;
            to.PregaoFinal = response.PregaoFinal;
            to.PregaoInicial = response.PregaoInicial;
            to.ValorMaximo = response.ValorMaximo;
            to.ValorMinimo = response.ValorMinimo;
            return to;
        }

        public ModelCollection<Model.DespesaNota> ToDespesaNota(List<Bovespa.Contabil.DespesaNota.DespesaNotaResponse> responseList)
        {
            ModelCollection<Model.DespesaNota> to = new ModelCollection<Sinacor.UI.Bovespa.Contabil.Model.DespesaNota>();

            foreach (Bovespa.Contabil.DespesaNota.DespesaNotaResponse item in responseList)
            {
                to.Add(ToDespesaNota(item));
            }
            return to;
        }
    }
}